const isProduction = process.env.NODE_ENV === "production";
module.exports = {
  productionSourceMap: !isProduction,
  outputDir: "dist",
  assetsDir: "static",
  configureWebpack: config => {
    if (!isProduction) return {};
  //  const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
      //.BundleAnalyzerPlugin;
    const CompressionPlugin = require("compression-webpack-plugin");
    return {
      externals: {
        vue: "Vue",
        "vue-router": "VueRouter",
        vuex: "Vuex",
        axios: "axios",
        "element-ui": "ELEMENT",
        nprogress: "NProgress",
        echarts: "echarts",
        "ali-oss": "OSS"
      },
      plugins: [
        //使用gzip压缩文件
        new CompressionPlugin({
          test: /\.js$|\.html$|\.css/,
          threshold: 2048,
          deleteOriginalAssets: false
        }),
       // new BundleAnalyzerPlugin()
      ]
    };
  },
  chainWebpack: config => {
    //关闭资源预加载
    // config.plugins.delete("prefetch");
  },
  devServer: {
    proxy: {
      "/api": {
        target: process.env.VUE_APP_HOST,
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          "^/api": ""
        }
      },
      "/api/resource": {
        target:
          "https://pro-platform.oss-cn-beijing.aliyuncs.com/exam/Resources",
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          "^/api/resource": ""
        }
      }
    }
  }
};
